package com.tanhua.dubbo.api;

import com.tanhua.model.mongo.Dimensions;
import org.apache.dubbo.config.annotation.DubboService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

/**
 * @Desciption:test
 * @Create by:金木yan
 * @Date: 2021/12/11 23:14
 */
@DubboService
public class DimensionsApiImpl implements DimensionsApi {
    @Autowired
    private MongoTemplate mongoTemplate;

    //根据报告id查询维度列表
    @Override
    public List<Dimensions> findByReportId(String reportId) {
        Query query = Query.query(Criteria.where("reportId").is(new ObjectId(reportId)));
        List<Dimensions> dimensionsList = mongoTemplate.find(query, Dimensions.class);
        return dimensionsList;
    }

    //保存维度数据
    @Override
    public void save(Dimensions dimensions) {
        //保存
        mongoTemplate.save(dimensions);
    }

    //根据报告id删除数据
    @Override
    public void deleteByReportId(ObjectId reportId) {
        Query query = Query.query(Criteria.where("reportId").is(reportId));
        mongoTemplate.remove(query, Dimensions.class);
    }
}
